package xquery;

import java.util.ArrayList;

import org.w3c.dom.Node;

public class XQuerySimpleExp extends XQuery {
	public enum Type { STRING, VAR }
	
	Type type;
	String value;
	
	@Override
	public XPathData eval(XQContext context, ArrayList<Node> currentNodeList) {
		switch(type) {
		case STRING:
			return new XPathData(value.substring(1, value.length()-1));
		case VAR:
			XPathData data = context.get(value);
			if(data.type ==  XPathData.Type.LIST)
			{
				ArrayList<Node> newList = new ArrayList<Node>();
				ArrayList<Node> oldList = data.getList();
				for(int i =0;i<oldList.size();i++)
				{
					newList.add(oldList.get(i));
				}
				return new XPathData(newList);
			}
			else
			{
				return data;
			}
		}
		
		return null;
	}
	public String toString()
	{
		return value;
	}
}
